package P041_MultiExtendWay;

import org.junit.Test;

/**
 * 多重继承成为实现，使用内部类实现
 * @author xufy1
 */
public class MultiExtendWay {

    /**
     * 内部类可以继承一个与外部类无关的类，保证内部类的独立性 是多重继承的一个关键
     */
    @Test
    public void test(){
        System.out.println(new Son().kind()+"   "+ new Son().strong());
        System.out.println(new Daughter().kind()+"   "+ new Daughter().strong());
    }

}

class Son extends FatherImpl implements  Mother{

    @Override
    public int strong() {
        return  super.strong() +1;
    }

    @Override
    public int kind() {
        return new MotherSpecial().kind();
    }

    /*public static void main(String[] args) {
        MotherSpecial motherSpecial = new MotherSpecial();
        int kind = motherSpecial.kind();

    }*/
    // java编程思想  java核心技术卷一
    /**
     * 内部类可以继承一个与外部类无关的类，保证内部类的独立性
     * 成员内部类(实例内部类 instance inner class)
     */
    private class MotherSpecial extends MotherImpl{
        public int kind(){
            return super.kind()-1;
        }
    }
}

class Daughter extends MotherImpl implements Father{
    @Override
    public int strong(){
            //匿名内部类
            return new FatherImpl(){
                public int strong(){
                    return super.strong()-2;
                }
        }.strong();
    }
}

class FatherImpl implements  Father{

    @Override
    public int strong() {
        return 8;
    }
}
class MotherImpl implements Mother{

    @Override
    public int kind() {
        return 8;
    }
}

interface Father{
     public int strong();
}
interface Mother{
    public int kind();
}